Please put both of this loops into one program. Set it up so that there is one main function and both loops are within it. Thank You.
import java.util.Scanner;
public class WhileDavidMungomaLab12 {
public static void main(String[] args) {
int aScore = -1;
while (aScore < 0 || aScore > 100) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a valid number that is within the
specified range(0 and 100): ");
aScore = sc.nextInt();
}
}
}
AND
import java.util.Scanner;
public class DoWhileDavidMungomaLab12 {
public static void main(String[] args) {
int aScore = -1;
do {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a valid number that is within the
specified range(0 and 100): ");
aScore = sc.nextInt();
} while (aScore < 0 || aScore > 100);
}
}
//WhileDavidMungomaLab12.java
import java.util.Scanner;
public class WhileDavidMungomaLab12 {
public static void main(String[] args) {
int aScore = -1;
while (aScore < 0 || aScore > 100) {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a valid number that is within the specified range(0 and 100): ");
aScore = sc.nextInt();
}
aScore = -1;
do {
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a valid number that is within the specified range(0 and 100): ");
aScore = sc.nextInt();
} while (aScore < 0 || aScore > 100);
}
}


Please put both of this loops into one program. Set it up so that there is...
I was wanting to know how would I call my add class through my if statement. Here is my class: import java.util.Scanner; public class Main { public static void main(String[] args) { int num1 = 0; int num2 = 0; int answer = 0; int userInput = 0; Scanner sc = new Scanner(System.in); System.out.println("Hello, this is a program where you can choose...
Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q { public static LinkedList<String> dogs = new LinkedList<String> (); public static LinkedList<String> cats = new LinkedList<String> (); public static LinkedList<String> animals = new LinkedList<String> (); public static void enqueueCats(){ System.out.println("Enter name"); Scanner sc=new Scanner(System.in); String name = sc.next(); cats.addLast(name); animals.addLast(name); } ...
Provide comments for this code explaining what each line of code does import java.util.*; public class Chpt8_Project { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int [][]courses=new int [10][2]; for(int i=0;i<10;i++) { while(true) { System.out.print("Enter classes and graduation year for student "+(i+1)+":"); courses[i][0]=sc.nextInt(); courses[i][1]=sc.nextInt(); if(courses[i][0]>=1...
package rectangle; public class Rectangle { private int height; private int width; public Rectangle(int aHeight, int aWidth) { super(); height = aHeight; width = aWidth; } public int getHeight() { return height; } public int getWidth() { return width; } public void setHeight(int aHeight) { height = aHeight; } public void setWidth(int aWidth) { width = aWidth; } public int...
I wrote two java classes. One is main and other one is getter and setter. I brought methods from Digit class to Main class to print result. However, for some reason, only welcome print statement got printed and others got ignored. On the output screen, only welcome statement appear. nDigit should be input from user. import java.util.Scanner; public class Main { public static void main(String[] args) { Digit digitGet = new Digit(); ...
This java code won't run and I can't figure out the problem with it. Please help import java.io.*; import java.util.*; import java.math.*; import java.util.Scanner; public class Fibonacci { // Returns n-th Fibonacci number static BigInteger fib(int n) { BigInteger[] Fibo = new BigInteger[n+2]; Fibo[0] = BigInteger.ZERO; Fibo[1] = BigInteger.ONE; for (int j=2 ; j<=n ; j++) { Fibo[j] = Fibo[j-1].add(Fibo[j-2]); } return (Fibo[n]); }...
What would be the output if 1, 2, 3, and -1 were entered and please walk me through the process. import java.util.Scanner; public class Practice1 { public static void main(String[] args) { int count = 0; int sum = 0; Scanner keyboard = new Scanner(System.in); System.out.println("Enter integers or -1 to quit"); int anInt = keyboard.nextInt(); while(anInt != -1) { anInt = keyboard.nextInt(); sum += anInt; count++; } anInt = keyboard.nextInt(); sum += anInt; count++; } }
Consider the following sample program: import java.util.Scanner; public class Palindrome { public static void main(String[] args){ Scanner kb = new Scanner(System.in); System.out.println("Enter a word:"); String word = kb.next(); String reverse = ""; for (int i=word.length()-1; i>=0; i--) reverse += word.charAt(i); boolean result = reverse.equalsIgnoreCase(word); if (result) System.out.println("The word " +word+ " is a Palindrome."); else System.out.println("The word " +word+ " is not a Palindrome."); } } Rewrite the program so that the main method is: public static void...
Please edit my following JAVA code so that there is no main function. I would like one function in this class that completes what the current program is trying to do so that I can call this class in my main class which will be separate. import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class enterwklyincme { private static DecimalFormat df = new DecimalFormat("0.00"); public static float readFloat(Scanner reader) { float num; while (true) { try { num = Float.parseFloat(reader.nextLine()); return...
Please Refactor this Assignment by using Arraylist instead of Array. import java.util.Scanner; public class DaysOfWeeks { public static void main(String[] args) { String DAY_OF_WEEKS[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; char ch; int n; Scanner scanner = new Scanner(System.in); do { System.out.print("Enter the day of the Week: "); n = scanner.nextInt() - 1; if (n >= 0 && n <= 6) System.out.println("The day of the week is " + DAY_OF_WEEKS[n] + "."); else System.out.println("Invalid Entry"); System.out.print("Try again (Y/N): "); ch = scanner.next().charAt(0); }while(ch=='Y'); }...