1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
algol [13]
3 years ago
14

Write a JAVA program containing a method called hasEight(), which takes an int as input and returns true if the number contains

the digit 8 (e.g., 18, 808). Your program must implement the method and take input from the user. Please upload only your .java file for full credit. Any other file type and programs without the hasEight() method will not receive any credit.
Computers and Technology
1 answer:
skelet666 [1.2K]3 years ago
7 0

Here's my code for that, consider it under the WTFPL (http://www.wtfpl.net/). Here is a pastebin of the code, as to avoid text formatting. (Link: https://pastebin.com/S3BDGxqm Raw: https://pastebin.com/raw/S3BDGxqm)

package javaapplication6;

import java.util.Scanner;

public class JavaApplication6 {

   

   public static void main(String[] args) {

       

       Scanner myScanner = new Scanner(System.in);

       

       boolean a;

       int s;

       System.out.println("Enter an int");

       s = myScanner.nextInt();

       a = hasEight(s);

       System.out.println(a);

       

   }

   private static boolean hasEight(int s)

   {

       String str = String.valueOf(s);

       return str.contains("8");

   }

   

}

You might be interested in
What is the difference between a Network Diagram and a Wiring Semantic?
stiks02 [169]

Answer:

Network diagram is the type of graphical networking chart that is basically used in the various type of computer telecommunication. The network diagram is useful for the networking designer and also for the network engineer for compiling the network documentation in detail.

Wiring semantic is the type of open source prototype platform which basically composed of the programming language and the IDE ( Integrated development environment). The wiring semantic consumer can affect the triggering the new data or information from the existing concepts.

7 0
3 years ago
A runner has a speed of 5m/ s and a mass of 130 kg. what is his kinetic energy?
kondaur [170]

Answer:

0.001625

Explanation:

if the velocity of an object is lower than 1% of light speed

8 0
2 years ago
Create a class Str that subclasses str. Add a method to the subclass that checks if the string does not start with a given strin
Stolb23 [73]

Answer:

#include <iostream>

using namespace std;

class Str{  ///baseclass

   public :

   string super_str;

   string getStr()

   {

       return super_str;

   }

   void setStr(string String)

   {

       super_str=String;

   }

};

class str : public Str{   //inheriting Str publicly

   public :

       string sub_str;

       string getstr()

       {

           return sub_str;

       }

       void setstr(string String)

       {

           sub_str=String;

       }

       bool notstartswith()

       {

           int n=sub_str.length();   //to find length of substr

           bool flag=false;

           for(int i=0;i<n;i++)     //Loop to check beginning of Str

           {

               if(super_str[i]!=sub_str[i])

               {

                   flag=true;

                   break;

               }

           }

           return flag;

       }

};

int main()

{

   str s;    //object of subclass

   s.setStr("Helloworld");  

   s.setstr("Hey");

   if(s.notstartswith()==1)     //checking if str is substring of Str

       cout<<"Str does not start with str";

   else

       cout<<"Str starts with str";

   return 0;

}

OUTPUT :

Str does not start with str

Explanation:

Above program is implemented the way as mentioned. for loop is being used to check the beginning of the str starts with substring or not.

3 0
3 years ago
Use the paragraph underneath to answer the four questions.
Xelga [282]
Wow...that’s a long paragraph
8 0
3 years ago
A foreign exchange student brought his desktop computer from his home in Europe to the United States. He brought a power adapter
lidiya [134]
The European plug takes up 220 volts while the American one takes 110 volts.
6 0
3 years ago
Other questions:
  • Write a program to prepare the monthly charge account statement for a customer of CS CARD International, a credit card company.
    11·1 answer
  • In which of the following situations may you pass on the right
    13·2 answers
  • Which shape denotes a process to be carried out in a flowchart?
    7·2 answers
  • 6. The NADH and FADH2 produced during the Krebs cycle pass their electrons down the 7. __ __ __ __ __ __ __ __ __ __ __ __ __ __
    6·1 answer
  • Blank spaces or unseen control characters in a data file are referred to as
    5·2 answers
  • My HTC Desire 510's mobile data stopped working, how to I make it work again?
    11·1 answer
  • Can anyone please help me to solve this question?
    10·1 answer
  • An algorithm requires numbers.<br> O True<br> O<br> False
    15·2 answers
  • Which type of infrastructure service stores and manages corporate data and provides capabilities for analyzing the data
    12·1 answer
  • Write a program using for loop to find the cube of numbers from 50-100 <br> FASTT
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!