Question

5) Write a java program with scanner object to input first number and second number as...

5) Write a java program with scanner object to input first number and second number as variable with input statement and system out print statement.

Steps:

1) Declare scanner object

2) Ask system out print for first number and declare variable first number

3) Ask system out print for second number and declare variable second number

4) Declare first for loop where variable int i has already a value (your choice), that i is less then equal to ? and i?

5) Declare the inner for loop where variable int j has already a value (your choice), that j is less then equal to ? and j?

6) Declare the variable sum where i and j use addition (or multiplication or subtraction/ your choice)

7) Declare the if condition where sum is greater then 8 (or your choice) then break statement

8) In the end print statement where i and j are using your computation of choice and displaying the sum. Note: be careful with bracket.

Homework Answers

Answer #1

Code:

import java.util.Scanner;

class loop
{
   public static void main(String[] args)
   {
       Scanner scnr=new Scanner(System.in);
       /*Creating the scanner object*/
       System.out.print("Enter the first number: ");
       int num1=scnr.nextInt();
       /*Reading first number*/
       System.out.print("Enter the second number: ");
       int num2=scnr.nextInt();
       /*Reading second number*/
       int i=0,j=1;
       /*initializing the i ,j*/
       for( i=0;i<5;i++)
       {
           for(j=1;j<5;j++)
           {
               int sum=i+j;
               /*Decalred sum and adding i and j*/
               if(sum>=8)
               {
                   break;
                   /*Breaking the loop when sum is grater than or equals 8*/
               }
           }
       }
       System.out.print("sum="+sum+" i="+i+" j="+j);  
       /*Finally printing the sum i and j*/
   }
}

Output:

Indentation:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
1) Write a java programming nested while loop where you will declare two numbers one for...
1) Write a java programming nested while loop where you will declare two numbers one for outer loop and the other one for inner while loop, and display the result. (Try using scanner) Steps: 1) Declare the variable of outer loop int and assign value of your choice 2) Declare while condition which outer variable is less the number of your choice 3) Declare variable of inner loop int and assign the value of your choice 4) Declare while condition...
5) Create a Java program using Scanner: Write a program where you will enter the grade...
5) Create a Java program using Scanner: Write a program where you will enter the grade score for 5 classes, then it will display total points and average and it will display the grade based on percentage. Steps: 1) Declare variable integer for English, Chemistry, Java Programming, Physics and Math 2) Declare variable total and percentage 3) Create Scanner object and prompt the user to enter grades for each class and input grades after each class 4) Calculate total of...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then you going to compute that amount with annual interest rate. 1) Prompt the user to enter student id, student name, student major 2) Declare variables consistent with names that you are prompting and relate them to the scanner 3) Declare the amount invested in college, prompt the user to ask for amount and declare variable and scanner to input 4) Declare the annual interest...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive...
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive the amount and declare the variable double amount for scanner Declare variable integer remaining amount which is equal to (int) (amount*100) Find the number of one dollars bt declaring the integer variable which is equal to remaining amount divided by 100 Declare: remaining amount %=100 Find the number of quarters: Declare integer variable number of quarters equal to remaining amount divided by 25 Declare:...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input and output with the Java console. Setup: Create a class called ConsolePractice with a main method. Create a static field in your class that stores a scanner object. You will use this scanner for all user input. private static Scanner scanner = new Scanner(System.in); Part A: Create a static method called “divide”. Your method should do the following: Accept two integers as parameters, a...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while...
4.2.2 Basic while loop with user input. JAVA Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. See "How to Use zyBooks". Also note: If the submitted code has an...
I need to sum a looped listbox in C#. I am adding a snip of my...
I need to sum a looped listbox in C#. I am adding a snip of my code. The user is to input the number of days that were worked. You get paid .01 for the first day and then that amount doubles per day worked. The code I am posting already does what it is supposed to do - it displays a list with the numbers of days worked with the amount of pay for that day listed beside it....
write a c++ program A class called car (as shown in the class diagram) contains: o...
write a c++ program A class called car (as shown in the class diagram) contains: o Four private variables: carId (int), carType (String), carSpeed (int) and numOfCars (int). numOfCars is a static counter that should be  Incremented whenever a new Car object is created.  Decremented whenever a Car object is destructed. o Two constructors (parametrized and copy constructor) and one destructor. o Getters and setters for the Car type, ID, and speed. And static getter function for numOfCars....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT