#Why is my output producing this fraction of the last print line?
1 messages ยท Page 1 of 1 (latest)
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Without seeing your code or the specific output you are referring to, it is difficult to provide a specific answer. However, there are a few common reasons why you might be experiencing unexpected output with fractions in Java:
-
Integer Division: If you perform division between two integers, Java will perform integer division and truncate the decimal portion of the result. For example, if you divide 5 by 2 (both integers), the result will be 2 instead of 2.5. To obtain a decimal result, you can cast one or both of the operands to a floating-point type (e.g., double).
-
Floating-Point Precision: Floating-point numbers in Java (e.g., float and double) have limited precision due to how they are represented in binary format. This can lead to rounding errors and unexpected results when performing calculations involving fractions.
-
Incorrect Mathematical Logic: It's possible that there is an error in your mathematical logic or formula that is causing unexpected results. Double-check your calculations and ensure that you are using the correct operators and formulas.
To troubleshoot the issue further, please provide more details about your code and the specific output you are getting.
import java.util.Scanner;
public class MadLib {
public static void main(String[] args) {
// declare and instantiate a Scanner
Scanner scnr = new Scanner(System.in);
System.out.println("Enter a whole number : ");
int num1 = scnr.nextInt();
System.out.println("Enter another whole number : ");
int num2 = scnr.nextInt();
System.out.println("Enter any number : ");
double num3 = scnr.nextDouble();
System.out.println("Enter a noun : ");
String noun1 = scnr.next();
System.out.println("Enter proper name : ");
String name = scnr.next();
System.out.println("Enter a verb : ");
String verb = scnr.next();
System.out.println("Enter an adjective : ");
String adj1 = scnr.next();
System.out.print("Enter another adjective : ");
String adj2 = scnr.next();
System.out.println("One day, " + num1 + " " + noun1 + "(s) wanted to cross a bridge over a river. Under that bridge lived a(n) " + adj1 + " Troll weighing " + num3 + " pounds, with " + num2 + " eyes and " + adj2 + " hair, named " + name + "." + name + " said to the " + noun1 + "(s) " + verb + " away, or I will have to eat you!"");
Why is it giving:
an adjective :
One day, 33 tree(s) wanted to cross a bridge over a river. Under that bridge lived a(n) dance Troll weighing 7.5 pounds, with 10 eyes and green hair, named Sam.Sam said to the tree(s) Smith away, or I will have to eat you!"
Why tf is "an adjective" being included?
When i println that adjective line I get:
er adjective :
(then the rest)